export default {
    name: "Sysreport",
    components: {},
    data() {
        return {
            height:'600',
            total:0,
            pagesize:5,
            currentPage:1,
            sysreportData:[
                {
                    operatname:'张三',
                    operatType:'类型',
                    operateContent:'内容内容',
                    createDate:'2019-2-2'
                },
                {
                    operatname:'张三',
                    operatType:'类型',
                    operateContent:'内容内容',
                    createDate:'2019-2-2'
                },
                {
                    operatname:'张三',
                    operatType:'类型',
                    operateContent:'内容内容',
                    createDate:'2019-2-2'
                },
                {
                    operatname:'张三',
                    operatType:'类型',
                    operateContent:'内容内容',
                    createDate:'2019-2-2'
                },
                {
                    operatname:'张三',
                    operatType:'类型',
                    operateContent:'内容内容',
                    createDate:'2019-2-2'
                },
                {
                    operatname:'张三',
                    operatType:'类型',
                    operateContent:'内容内容',
                    createDate:'2019-2-2'
                },
            ],
            multipleSelection:[],
            timeInterval: [this.NowTimestamp((new Date()).getTime() - 4665600000), this.NowTimestamp((new Date()).getTime())],
        };
    },
    computed: {},
    watch: {},
    created() {
        this.initSysreportList();
     },
    mounted() { },
    methods: {
        NowTimestamp(timestamp) {
            var date = new Date(timestamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
            var Y = date.getFullYear() + '-';
            var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
            var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate() + ' ');
            var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
            var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
            var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
            return Y + M + D;
        },
        //异常报表查询
        initSysreportList() {
            this.$http.get("")
             .then((res) => {
               if(res.status == 200){
                  this.sysreportData = res.rows;
                  this.total = res.total;
               }
             }).catch((err) => {
               console.log(err);
           });
        },
        //导出excel表格
        exportClick() {
            //导出修正文件名--利用a标签
            this.$http.post('', this.qs.stringify({
                limit: this.pagesize,
                offset: this.offset,
                //deviceType: this.deviceType, //设备型号
                //startDate: this.timeInterval[0] + ' 00:00:00',
                //endDate: this.timeInterval[1] + ' 23:59:59',
            }), {
                responseType: 'arraybuffer'
            }).then((res) => {
                 if (res.status == 200) {
                    const content = res.file;
                    const blob = new Blob([content], {
                    type: "application/vnd.ms-excel"
                    })
                    const fileName = "异常报表&" +this.timeInterval[0] + 'To' +this.timeInterval[1] + '.xls' ;
                    if('download' in document.createElement('a')){
                       //非IE下载
                       const elink = document.createElement("a");
                       elink.download = fileName;
                       elink.style.display = "none";
                       elink.href = URL.createObjectURL(blob);
                       document.body.appendChild(elink);
                       elink.click();
                       URL.revokeObjectURL(elink.href);//释放URL对象
                       document.body.removeChild(elink);
                    } else {
                        //IE10下载
                        navigator.msSaveBlob(blob,fileName);
                    }
                 }
             }).catch((err) => {
              console.log(err);
          });
        },
        toggleSelection(rows) {
            if (rows) {
                rows.forEach(row => {
                    this.$refs.multipleTable.toggleSelection(row);
                });
            } else {
                this.$refs.multipleTable.clearSelection();
            }
        },
        handleSelectionChange(val){
          this.multipleSelection = val;
        },
        handleSizeChange(val){
          this.pagesize = val;
          this.initSysreportList();
        },
        handleCurrentChange(val){
          this.currentPage = val;
          this.initSysreportList();
        }
    }
};